package com.corpdata.common.upload.controller;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import com.corpdata.common.upload.entity.SysAttachment;
import com.corpdata.common.upload.service.SysAttachmentService;
import com.corpdata.common.domain.DataGridRequestDTO;
import com.corpdata.common.result.Result;
import com.corpdata.system.log.WebLog;
import com.corpdata.core.base.BaseController;

/**
 * 
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-07-26 10:32:32
 */
 
@Controller
@RequestMapping("common/upload")
public class SysAttachmentController extends BaseController{

	@Autowired
	private SysAttachmentService sysAttachmentService;
	
	//新增页面
	@GetMapping("/add")
	public String add(){
		return "common/upload/sysAttachment_add";
	}
	
	//保存数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/save")
	public Result save(SysAttachment record){
		return sysAttachmentService.save(record);
	}
	
	//编辑页面
	@RequestMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id,ModelMap map){
		map.put("record", sysAttachmentService.findById(id));
		return "common/upload/sysAttachment_edit";
	}
	
	//更新数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/update")
	public Result update(SysAttachment record){
		return sysAttachmentService.update(record);
	}
	
	//删除
	@WebLog()
	@ResponseBody
	@PostMapping("/delete")
	public Result delete(String id){
		return sysAttachmentService.deleteById(id);
	}
	
	//批量删除
	@WebLog()
	@ResponseBody
	@PostMapping("/deletes")
	public Result deletes(@RequestParam("ids[]") String[] ids){
		return sysAttachmentService.deleteByIds(ids);
	}
	
	//详情页面
	@GetMapping("/details/{id}")
	public String details(ModelMap map,@PathVariable("id") String id){
		map.put("record", sysAttachmentService.findById(id));
	    return "common/upload/sysAttachment_details";
	}
	
	//列表页面
	@GetMapping("/list")
	public String list(){
	    return "common/upload/sysAttachment_list";
	}
	
	//列表数据
	@ResponseBody
	@RequestMapping("/listdata")
	public String findByPage(DataGridRequestDTO dgRequest){
		return sysAttachmentService.findByPage(dgRequest);
	}
	//新增附件
	@ResponseBody
	@RequestMapping("/add/{id}")
	public Map<String,Object> add(@PathVariable("id") String id,HttpServletRequest request) throws IOException {
		return sysAttachmentService.insert(id,request);
	}
	
}
